/*
 *    Copyright © OpenAtom Foundation.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.inspur.edp.bef.dtgenerator.entity.entitydata;

import com.inspur.edp.bef.bizentity.GspBizEntityObject;
import com.inspur.edp.bef.dtgenerator.DotNetToJavaStringHelper;
import com.inspur.edp.bef.dtgenerator.entity.entitynode.BENodeGeneratorContext;
import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.cef.generator.entityGenerator.entity.entityData.EntityDataGenerator;
import java.util.ArrayList;

public class BEEntityDataGenerator extends EntityDataGenerator {
  private BENodeGeneratorContext beNodeGenCtx;
  private GspBizEntityObject currentObject;

  public BEEntityDataGenerator(
      BENodeGeneratorContext beNodeGenCtx, GspBizEntityObject currentObject) {
    super(beNodeGenCtx, currentObject);
    this.beNodeGenCtx = beNodeGenCtx;
    this.currentObject = currentObject;
  }

  @Override
  protected java.util.ArrayList<com.inspur.edp.caf.generator.baseInfo.TypeInfo>
      addParentInterfaces() {

    return super.addParentInterfaces();
    //    // wj-dbe已改
//    var rez =
    //        ((super.addParentInterfaces()) != null)
    //            ? super.addParentInterfaces()
    //            : new java.util.ArrayList<java.lang.Class>();
    //    if (!beNodeGenCtx.BefRtEntityGenCtx.BEGenCtx.getIsParentBEInSameProj()) {
    //      rez.Add(
    //          beNodeGenCtx
    //              .BefRtEntityGenCtx
    //              .BEGenCtx
    //              .getParentBEAssembly()
    //              .GetType(GetParentClassName()));
    //    }
    //    return rez;
  }

  @Override
  protected ArrayList<TypeInfo> addExtendParentInterfaces() {
    ArrayList<TypeInfo> result = super.addExtendParentInterfaces();
    if (result == null) {
      result = new ArrayList<>();
      }
    if (!DotNetToJavaStringHelper.isNullOrEmpty(
            beNodeGenCtx.getBefEntityGenCtx().getBEGenCtx().getBE().getDependentEntityId())
        && beNodeGenCtx.getBefEntityGenCtx().getBEGenCtx().getIsParentBEInSameProj()) {
      result.add(new TypeInfo(getParentClassName()));
    }
    return result;
  }

  private String getParentClassName() {
    return beNodeGenCtx
            .getBefEntityGenCtx()
            .getBEGenCtx()
            .getParentBE()
            .getDependentEntityPackageName()
        + "."
        + getName(currentObject);
  }
}
